//
//  IGCommentZuoPinCell.m
//  jingdongfang
//
//  Created by BOE on 2018/5/17.
//  Copyright © 2018年 BOE-SBG-CTO. All rights reserved.
//

#import "IGCommentZuoPinCell.h"

@interface IGCommentZuoPinCell()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *authorLabel;

@end
@implementation IGCommentZuoPinCell

+ (IGCommentZuoPinCell *)cellWithTableView:(UITableView *)tableView
{
    IGCommentZuoPinCell *cell = [tableView dequeueReusableCellWithIdentifier:@"kIGCommentZuoPinCell"];
    if (!cell) {
        cell = [[IGCommentZuoPinCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"kIGCommentZuoPinCell"];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}

- (void)createUI {
    _imgView = [[UIImageView alloc] init];
    _nameLabel = [UILabel new];
    _authorLabel = [UILabel new];
    
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    _nameLabel.font = [UIFont systemFontOfSize:20];
    _nameLabel.textColor = [UIColor c4Color];
    _authorLabel.textAlignment = NSTextAlignmentRight;
    _authorLabel.font = [UIFont systemFontOfSize:20];
    _authorLabel.textColor = [UIColor appColor];
    
    [self.contentView addSubview:self.imgView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.authorLabel];
    
    [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-50);
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo((KSCREENWIDTH-30)/2);
    }];
    
    [_authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo((KSCREENWIDTH-30)/2);
    }];
}

- (void)setModel:(IGArtWorkModel *)model {
    _model = model;
    
    if ([model.plates intValue] == 2) {
        [_imgView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(-50);
            make.width.mas_equalTo(211);
            make.centerX.mas_equalTo(self.mas_centerX);
        }];
    }
    [_imgView sd_setImageWithURL:[NSURL URLWithString:model.image]];
    _nameLabel.text = model.title;
    _authorLabel.text = model.uploader;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
